<?php

namespace common\models;

use Yii;
use himiklab\sitemap\behaviors\SitemapBehavior;
use yii\helpers\Url;
/**
 * This is the model class for table "post".
 *
 * @property integer $id
 * @property integer $cid
 * @property string $title
 * @property string $author
 * @property string $description
 * @property string $content
 * @property string $img
 * @property string $tag
 * @property integer $view
 * @property integer $enable
 * @property string $url
 * @property integer $created_at
 * @property integer $updated_at
 */
class Post extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'post';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['cid', 'view', 'enable', 'created_at', 'updated_at'], 'integer'],
            [['content'], 'string'],
            [['title', 'img'], 'string', 'max' => 100],
            [['author'], 'string', 'max' => 20],
            [['description', 'url'], 'string', 'max' => 255],
            [['tag'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', 'ID'),
            'cid' => Yii::t('common', 'Cid'),
            'title' => Yii::t('common', 'Title'),
            'author' => Yii::t('common', 'Author'),
            'description' => Yii::t('common', 'Description'),
            'content' => Yii::t('common', 'Content'),
            'img' => Yii::t('common', 'Img'),
            'tag' => Yii::t('common', 'Tag'),
            'view' => Yii::t('common', 'View'),
            'enable' => Yii::t('common', 'Enable'),
            'url' => Yii::t('common', 'Url'),
            'created_at' => Yii::t('common', 'Created At'),
            'updated_at' => Yii::t('common', 'Updated At'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getC()
    {
        return $this->hasOne(Subject::className(), ['id' => 'cid'])->inverseOf('posts');
    }

    /**
     * 设置自动更新时间   created_at | updated_at 字段类型为 int(11) 
     */
    public function behaviors() {
        return [
            \yii\behaviors\TimestampBehavior::className(),
        ];
    }	
}
